app.controller("index", function ($scope, $http, $rootScope, $sce) {
    $http({
        method: "get",
        url: "/index",
    }).success(function (data) {
        console.log(data);
        $scope.Data = data;
        $scope.$emit("toRoot", data.menus);
        $scope.companyIntr = $sce.trustAsHtml(data.setup.introduce)
    })
    $scope.tagShow = false;
    $scope.showTag = function () {
        $scope.tagShow = !$scope.tagShow;
    }
    console.log(1);
    $scope.tagTitle = "切换校区"
    $scope.selectTag = function (name) {
        $scope.tagTitle = name;
        $scope.tagShow = false;
    }
    // $scope.selectPage=function(page,$event){
    //     console.log(page);
    // }   
})
app.controller("home", function ($scope, $http) {
    console.log("home")
    $http({
        method: "get",
        url: "/home/index",
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.studentTypes = data.studentTypes;
        console.log($scope.studentTypes);
        $scope.bannerData = [];
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
        $scope.initOption = {
            techOrder: ["html5", "flash"]
        };
        $scope.player = neplayer("my-video", $scope.initOption, function () {
            $scope.player.setDataSource({
                type: "video/mp4",
                src: "http://vodxrsres3h.vod.126.net/vodxrsres3h/RjI3EVEH_1081898_shd.mp4"
            });
        })

    })

    $scope.$watch("majorTypeId", function (data) {
        if (data) {
            $scope.majorTypeId = data;
        }
    })
    //获取专业分类
    // $http({
    //     method: "get",
    //     url: "/service",
    // }).success(function(data) {
    //     console.log(data);
    //     $scope.majorData = data.majorTypes;
    // })
    $scope.index1 = 0;
    $scope.selectImg1 = function (i) {
        $scope.index1 = i;
    }
    $scope.index2 = 0;
    $scope.selectImg2 = function (i) {
        $scope.index2 = i;
    }
    $scope.myInterval = 2000;
    $scope.noWrapSlides = false;
    $scope.active = 0;
    $scope.index3 = 0;
    $scope.showStudent = function (i) {
        $scope.index3 = i;
    }
})
app.controller("about", function ($scope, $state, $http, $sce) {
    console.log($state.params);
    $scope.params = $state.params;
    $http({
        method: "get",
        url: "/API/queryData/" + $state.params.paramId + "/" + $state.params.page,
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.currentPage = data.page;
        $scope.content = $sce.trustAsHtml(data.datas[0].content);
        $scope.bannerData = [];
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
    })
    $scope.pageChange = function () {
        $state.go("about", { paramId: $state.params.paramId, page: $scope.currentPage })
    }
})
app.controller("business", function ($scope, $state, $http) {
    $scope.params = $state.params;
    $http({
        method: "get",
        url: "/API/queryData/" + $state.params.paramId + "/1",
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.currentPage = data.page;
        $scope.bannerData = [];
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
        // if(data.menu.eName=="academicEducation"||data.menu.eName=="school"){
        if (data.menu.eName == "academicEducation" || data.menu.eName == "school") {

            $http({
                method: "get",
                url: "/service",
            }).success(function (data) {
                console.log(data);

                $scope.selectData = data;
                $scope.majorData = data.majors;
                console.log($scope.majorData);

                $scope.selectData = data;
                $scope.majorData = data.majors;

            })
        }
        if (data.menu.eName == "cooperativeSchool") {
            $http({
                method: "get",
                url: "/service",
            }).success(function (data) {
                console.log(data);
                $scope.schoolData = data;

            })
        }
    })
    $scope.arrow = false;
    $scope.showAll = function () {
        $scope.arrow = !$scope.arrow;
        if ($scope.arrow) {
            $(".majorSelect .top").css({ "height": "auto" })
            $(".majorSelect .arrow i").removeClass("icon-jiantou-copy").addClass("icon-jiantou-copy1")
        } else {
            $(".majorSelect .top").css({ "height": "35px" })
            $(".majorSelect .arrow i").removeClass("icon-jiantou-copy1").addClass("icon-jiantou-copy")
        }
    }
    $scope.showMajor = false;
    $scope.showAllMajor = function () {
        $scope.showMajor = !$scope.showMajor;
        if ($scope.showMajor) {
            $(".majorSelect .top").css({ "height": "auto" });
            $(".major").css({ "height": "auto" });
            $(".majorSelect").css({ "height": "auto" });

        } else {
            $(".majorSelect .top").css({ "height": "35px" });
            $(".major").css({ "height": "35px;" });
            $(".majorSelect").css({ "height": "35px" });
        }
    }
    $scope.kindId = 0;
    $scope.majorTypeId = 0;
    $scope.majorId = 0;
    $scope.majorLevelId = 0;
    $scope.siteId = 0;
    $scope.conditionData = [];
    $scope.arr = [];
    $scope.majorName = [];
    $scope.select = function (key, value, name) {
        var i = $scope.arr.indexOf(key);
        $scope.condition = { "key": key, "value": value, "name": name };
        if ($scope.arr.indexOf(key) < 0) {
            $scope.arr.push(key);
            $scope.conditionData.push($scope.condition);

        } else {
            $scope.conditionData[i] = $scope.condition;
        }
        console.log($scope.conditionData);
        if (key == 'kind') {
            $scope.kindId = value;
        } else if (key == 'majorType') {
            $scope.majorTypeId = value;
            if (value != 0) {
                var arr2 = []
                angular.forEach($scope.selectData.majors, function (data) {
                    if (data.typeId == value) {
                        arr2.push(data)
                    }
                })
                $scope.majorData = arr2;
            } else {
                $scope.majorData = $scope.selectData.majors;
            }
        } else if (key == 'major') {
            $scope.majorName.name = name;
            $scope.majorName.id = value;
            $scope.majorId = value;
        } else if (key == 'majorLevel') {
            $scope.majorLevelId = value;
        } else if (key == 'site') {
            $scope.siteId = value;
        }
        $http({
            method: "get",
            url: "/service/search/" + $scope.kindId + "/" + $scope.majorTypeId + "/" + $scope.majorId + "/" + $scope.majorLevelId + "/" + $scope.siteId,
        }).success(function (data) {
            console.log(data);
            $scope.selectData.datas = data.datas;
        })
    }
    $scope.del = function (data, index, e) {
        $scope.conditionData.splice(index, 1);
        if (data.key == 'kind') {
            $scope.kindId = 0;
        } else if (data.key == 'majorType') {
            $scope.majorTypeId = 0;
        } else if (data.key == 'major') {
            $scope.majorId = 0;
        } else if (data.key == 'major') {
            $scope.majorId = 0;
        } else if (data.key == 'majorLevel') {
            $scope.majorLevelId = 0;
        } else if (data.key == 'siteId') {
            $scope.siteId = 0;
        }
        $http({
            method: "get",
            url: "/service/search/" + $scope.kindId + "/" + $scope.majorTypeId + "/" + $scope.majorId + "/" + $scope.majorLevelId + "/" + $scope.siteId,
        }).success(function (data) {
            console.log(data);
            $scope.selectData.datas = data.datas;
            $scope.majorName = "";

        })
    }
})
app.controller("schoolDetail", function ($scope, $state, $http, $sce, $rootScope) {
    // console.log($state.params);
    // $scope.params=$state.params;
    $http({
        method: "get",
        url: "/service/detail/" + $state.params.schoolId,
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.content = $sce.trustAsHtml(data.data.detail);
        $rootScope.title = "华博特教育集团-" + data.data.name;
        $rootScope.keyword = "华博特教育集团-" + data.data.introduce + "-" + data.data.kindName + "-" + data.data.levelName + "-" + data.data.majorName + "-" + data.data.name;
        $rootScope.discription = $rootScope.keyword;
    })
})
app.controller("student", function ($scope, $state, $http, $rootScope) {
    console.log($state.params);
    $scope.params = $state.params;
    $http({
        method: "get",
        url: "/API/queryData/" + $state.params.paramId + "/" + $state.params.page,
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.currentPage = data.page;
        $scope.bannerData = [];
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
    })
    $scope.pageChange = function () {
        $state.go("student", { paramId: $state.params.paramId, page: $scope.currentPage })
    }

})
app.controller("notice", function ($scope, $state, $http) {
    console.log($state.params.paramId);
    $scope.params = $state.params;
    console.log($scope.params);
    $http({
        method: "get",
        url: "/API/queryData/" + $state.params.paramId + "/" + $state.params.page,
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.currentPage = data.page;
        $scope.bannerData = [];
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
    })
    $scope.pageChange = function () {
        $state.go("notice", { paramId: $state.params.paramId, page: $scope.currentPage })
    }
})
app.controller("connect", function ($scope, $http, $state, $sce) {
    $scope.params = $state.params;
    $http({
        method: "get",
        url: "/API/queryData/" + $state.params.paramId + "/" + $state.params.page,
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.content = $sce.trustAsHtml(data.datas[0].content);
        console.log($scope.content);
        $scope.bannerData = [];
        $scope.currentPage = data.page;
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
        if (data.menu.eName == 'enroll') {
            $http({
                method: "get",
                url: "/student/index",
            }).success(function (data) {
                data.schools.push({ id: "0", name: "其他学校" });
                console.log(data);
                $scope.enrollData = data;

            })
        }
    })
    $scope.pageChange = function () {
        // console.log($scope.currentPage);
        $state.go("connect", { paramId: $state.params.paramId, page: $scope.currentPage })
    }
    $scope.schoolSelect = function (schoolName, schoolId) {
        $scope.school = schoolName;
        $scope.schoolId = schoolId;
    }
    $scope.majorSelect = function (majorName, majorId) {
        $scope.major = majorName;
        $scope.majorId = majorId;
    }
    $scope.postForm = function () {


        console.log($scope.abc)
        if (!$("input[name='name']").val()) {
            alert("姓名为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='mobile']").val()) {
            alert("电话为必填项，请重新填写！");
            return;
        }
        if (!$("select[name='majorTypeId']").val()) {
            alert("兴趣专业为必填项，请重新填写！");
            return;
        }
        $("form").ajaxSubmit({
            type: "post",
            dataType: "json",
            url: "/student/submitOrder",
            success: function (data) {
                console.log(data);
                if (data.code == 0) {
                    alert(data.msg)
                }
                // successCall(data);
                // $rootScope.loadStatus=false;
            },
            fail: function (data) {
                // $rootScope.loadStatus=false;
                // errorCall(data);
            }
        })
        // if($scope.formName.name.$error){
        //     alert("姓名为必填项，请重新编辑！")
        // }
    }
})
app.controller("detail", function ($scope, $http, $state, $sce, $rootScope) {
    $scope.paramId = $state.params.paramId;
    $scope.$watch('Data', function (data) {
        if (data) {
            angular.forEach($scope.Data.menus, function (data) {
                if (data.id == $scope.paramId) {
                    $scope.currNav = data;
                    if (data.upId) {
                        console.log(data.upId);
                        angular.forEach($scope.Data.menus, function (item) {
                            if (data.upId == item.id) {
                                $scope.upNav = item;
                            }
                        })
                    }
                }

            })
            // console.log($scope.paramId);
        }
    })


    $http({
        method: "get",
        url: "/API/queryDetail/" + $state.params.contentId,
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.content = $sce.trustAsHtml(data.data.content)
        //  $scope.currentPage =data.page;
        $rootScope.title = "华博特教育集团-" + data.data.name;
        $rootScope.keyword = data.data.keyword;
        $rootScope.discription = data.data.discription;
    })
})
app.controller("enroll", function ($scope, $state, $http, $interval) {
    console.log($state.params);
    $scope.params = $state.params;
    $http({
        method: "get",
        url: "/API/queryData/" + $state.params.paramId + "/1",
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.currentPage = data.page;
        $scope.bannerData = [];
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
        if (data.menu.eName == 'reservation') {
            $http({
                method: "get",
                url: "/student/index"
            }).success(function (data) {
                data.schools.push({ id: "0", name: "其他学校" });
                console.log(data);
                $scope.enrollData = data;
            })
        }
        if (data.menu.eName == 'apply') {
            $scope.examZone = [
                [],
                ["杭州", '杭州萧山', "杭州桐庐", "杭州富阳", "杭州临安", '杭州余杭', "杭州建德", "杭州淳安", "宁波", "宁波北仑", "宁波镇海", "宁波慈溪", "宁波余姚", "宁波奉化",
                    "宁波象山", "宁波宁海", "宁波鄞州", "温州", "嘉兴", "湖州", "绍兴-绍兴市", "衢州柯城", "丽水莲都区", "台州椒江", "舟山定海", "金华义乌"],
                ["杭州", '杭州萧山', "杭州桐庐", "杭州富阳", "杭州临安", '杭州余杭', "杭州建德", "杭州淳安", "宁波", "宁波慈溪", "宁波余姚", "温州", "嘉兴", "湖州", "绍兴-绍兴市"
                    , "金华-金华市", "衢州柯城", "丽水丽水市", "台州市", "舟山市"]
            ]
            $http({
                method: "get",
                url: "/student/index",
            }).success(function (data) {
                console.log(data);
                $scope.enrollData = data;
            })
            $scope.levelSelect = function (level) {
                console.log(level)
                if (level == 0) {
                    $scope.examZoneData = $scope.examZone[1];
                } else if (level == 1 || level == 2) {
                    $scope.examZoneData = $scope.examZone[2];
                }
            }
        }
    })

    $scope.postForm = function () {
        if (!$("input[name='name']").val()) {
            alert("姓名为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='mobile']").val()) {
            alert("电话为必填项，请重新填写！");
            return;
        }
        if (!$("select[name='majorTypeId']").val()) {
            alert("兴趣专业为必填项，请重新填写！");
            return;
        }
        $("#form1").ajaxSubmit({
            type: "post",
            dataType: "json",
            url: "/student/submitOrder",
            success: function (data) {
                console.log(data);
                if (data.code == 0) {
                    alert(data.msg)
                }
            },
            fail: function (data) { }
        })
    }
    $scope.status = 0;
    $scope.fileChange = function (e) {
        $scope.status++;
        var className = $(e).attr("id")
        var url = URL.createObjectURL($(e)[0].files[0]);
        $(e).prev().attr('src', url);
        $.ajaxFileUpload({
            url: "/Upload/uploadImg",
            fileElementId: $(e).attr("id"),
            type: 'post',
            dataType: 'text',
            secureuri: false,
            success: function (data) {
                $scope.status--;
                className = "." + className;
                $(className).val(data);
            },
            error: function (data, status, e) {
            }
        });
    }
    $scope.postForm2 = function () {
        if (!$("input[name='name']").val()) {
            alert("姓名为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='birthday']").val()) {
            alert("出生年月为必填项，请重新填写！");
            return;
        }
        if (!$("select[name='sex']").val()) {
            alert("性别为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='cardId']").val()) {
            alert("身份证号为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='nation']").val()) {
            alert("民族为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='phone']").val()) {
            alert("联系电话为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='political']").val()) {
            alert("政治面貌为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='address']").val()) {
            alert("通讯地址为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='zipCode']").val()) {
            alert("邮政编码为必填项，请重新填写！");
            return;
        }
        if (!$("select[name='levelId']").val()) {
            alert("报考层次为必填项，请重新填写！");
            return;
        }
        if (!$("select[name='examZone']").val()) {
            alert("考区为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='graduateDate']").val()) {
            alert("毕业日期为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='orderSchool1']").val()) {
            alert("报考院校志愿一为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='orderMajor1']").val()) {
            alert("报考专业志愿一为必填项，请重新填写！");
            return;
        }
        if (!$("input[name='graduateSchool']").val()) {
            alert("毕业学校为必填项，请重新填写！");
            return;
        }
        if (!$("select[name='education']").val()) {
            alert("文化程度为必填项，请重新填写！");
            return;
        }
        //if (!$("input[name='picture1']").val()) {
        //    alert("身份证正面照为必选项，请重新选择！");
        //    return;
        //}
        //if (!$("input[name='picture2']").val()) {
        //    alert("身份证反面照为必选项，请重新选择！");
        //    return;
        //}
        //if (!$("input[name='picture3']").val()) {
        //    alert("一寸蓝底照片为必选项，请重新选择！");
        //    return;
        //}
        if (!$scope.status) {
            $("#form2").ajaxSubmit({
                type: "post",
                dataType: "json",
                // student/submit
                url: "student/submit",
                success: function (data) {
                    console.log(data);
                    if (data.code == 0) {
                        alert(data.msg)
                    } else {
                        alert(data.msg)
                    }
                },
                fail: function (data) { }
            })
        } else {
            var timer = $interval(function () {
                if (!$scope.status) {
                    $interval.cancel(timer);
                    $("#form2").ajaxSubmit({
                        type: "post",
                        dataType: "json",
                        // student/submit
                        url: "student/submit",
                        success: function (data) {
                            console.log(data);
                            if (data.code == 0) {
                                alert(data.msg)
                            } else {
                                alert(data.msg)
                            }
                        },
                        fail: function (data) { }
                    })
                }
            }, 100)
        }

    }
})
app.controller("school", function ($scope, $state, $http) {
    $http({
        method: "get",
        url: "/API/queryData/" + $state.params.paramId + "/1",
    }).success(function (data) {
        $scope.data = data;
        $scope.bannerData = [];
        angular.forEach($scope.data.banners, function (data) {
            if (data.kind == 0) {
                $scope.bannerData.push(data);
            }
        })
    })
    $http({
        method: "get",
        url: "/service",
    }).success(function (data) {
        console.log(data);
        $scope.selectData = data;
        $scope.schoolData = data.datas;
        $scope.schoolIntr = data.datas[0];
        $scope.click = function (i) {
            $scope.schoolIntr = data.datas[i];
        }
    })
    $scope.kindId = 0;
    $scope.majorTypeId = 0;
    $scope.majorId = 0;
    $scope.majorLevelId = 0;
    $scope.siteId = 0;
    $scope.select = function (key, value) {

        console.log(key);
        console.log(value);
        if (key == 'kind') {
            $scope.kindId = value;
        } else if (key == 'majorType') {
            $scope.majorTypeId = value;
        } else if (key == 'major') {
            $scope.majorId = value;
        } else if (key == 'major') {
            $scope.majorId = value;
        } else if (key == 'majorLevel') {
            $scope.majorLevelId = value;
        } else if (key == 'siteId') {
            $scope.siteId = value;
        }
        $http({
            method: "get",
            url: "/service/search/" + $scope.kindId + "/" + $scope.majorTypeId + "/" + $scope.majorId + "/" + $scope.majorLevelId + "/" + $scope.siteId,
        }).success(function (data) {
            console.log(data);
            $scope.selectData.datas = data.datas;
        })
    }
})
app.controller("majorDetail", function ($scope, $state, $http, $sce, $rootScope) {
    // console.log($state.params);
    // $scope.params=$state.params;
    $http({
        method: "get",
        url: "/service/getMajor/" + $state.params.majorId,
    }).success(function (data) {
        console.log(data);
        $scope.data = data;
        $scope.content = $sce.trustAsHtml(data.detail);
        $rootScope.title = "华博特教育集团-" + data.name;
        $rootScope.keyword = "华博特教育集团-" + data.name;
        // $rootScope.discription = $rootScope.keyword;
    })
})